package com.ywk.zzh.mongotest.controller;

import com.ywk.zzh.mongotest.document.User;
import com.ywk.zzh.mongotest.service.UserService;
import com.ywk.zzh.mongotest.vo.Page;
import com.ywk.zzh.mongotest.vo.UserQueryVo;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/mongo")
public class UserController {

    private final UserService userService;

    @GetMapping("/list")
    public Page<User> list(@RequestBody UserQueryVo vo) {
        return userService.list(vo);
    }

    @GetMapping("/getById/{id}")
    public User getById(@PathVariable Long id) {
        return userService.getById(id);
    }

    @PostMapping("/save")
    public Long saveUser(@RequestBody User  user) {
        userService.insert(user);
        return user.getId();
    }

    @PostMapping("/update")
    public Long updateUser(@RequestBody User  user) {
        userService.update(user);
        return user.getId();
    }

}
